﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using SERP.StringMappings;
using SERP.DAO;
using SERP.Controllers;
namespace SERP.Modules.Organizations{
	public partial class OrganizationsEdit : SERP.Modules.ModuleBase
	{
		private OrganizationsController controller = new OrganizationsController();    
		protected void Page_Load(object sender, EventArgs e){		
			LoadLanguage();	
			if(!this.IsPostBack){
				BindInfo();			
			}
		}   
		//Load All lable text
		private void LoadLanguage(){
			this.lblTitle.InnerText=SERP.Constants.APP_EDIT_TITLE+" "+OrganizationsStringMapping.Organizations;
			this.btnSave.Text =  Constants.APP_SAVE;
			this.btnOK.Text =  Constants.APP_CLOSE;
			this.btnBack.Text =  Constants.APP_CANCEL;
		}
		private OrganizationsEntity GetObject(){
			controller.LoadObject(Int32.Parse(Request["OrganizationId"]));
			return controller.OrganizationsObject;
		}
		private void BindInfo(){
			OrganizationsEntity o=GetObject();		
			inputControl.Model=o;
			inputControl.UpdateToScreen();
		}       
		private bool Save(){
			inputControl.UpdateToModel();
			return controller.Update();
		}
		private void GoBack(){
			RedirectToPage("OrganizationsList");
		}
		protected void OnSave(object sender, EventArgs e){
			GetObject();
			inputControl.Model=controller.OrganizationsObject;
			if(!inputControl.ValidateScreen())
			{
				return;
			}
			if(Save()){
				lblInfo.Text=SERP.Constants.MSS_SUCCESS;
			}
			else{
				lblInfo.Text=SERP.Constants.MSS_FAILE;
			}
			MultiView1.ActiveViewIndex=1;
		}
		protected void OnCancel(object sender, EventArgs e){
			GoBack();
		}   
}
}
